<?php


namespace app\seller\controller;

use think\Db;


class Setting extends Base
{
    public function shop()
    {
        $images = explode(",", $this->shop['images']);
        foreach ($images as &$item) {
            $item = cdnurl($item, true);
        }
        return $this->success('获取成功', [
            'dizhi' => $this->shop['dizhi'],
            'hall_lock_id' => $this->shop['hall_lock_id'],
            'name' => $this->shop['name'],
            'phone' => $this->shop['phone'],
            'business_time' => $this->shop['business_stare_time'] . "-" . $this->shop['business_end_time'],
            'business_stare_time' => $this->shop['business_stare_time'],
            'business_end_time' => $this->shop['business_end_time'],
            'image' => cdnurl($this->shop['image'], true),
            'images' => $images,
            'port' => $this->shop['port']
        ]);
    }

    public function other()
    {
        return $this->success('获取成功', [
            'wifi_ssid' => $this->shop['wifi_ssid'],
            'wifi_password' => $this->shop['wifi_password'],
            'end_time_min' => $this->shop['end_time_min'],
            'end_time_content' => $this->shop['end_time_content'],
        ]);
    }

    public function setport()
    {
        $port = input('port');
        $res = Db::table('fa_category')->where([
            'id' => $this->shop_id,
        ])->update([
            'port' => $port,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改地址
    public function sethalllock()
    {
        $hall_lock_id = input('hall_lock_id');
        $res = Db::table('fa_category')->where([
            'id' => $this->shop_id,
        ])->update([
            'hall_lock_id' => $hall_lock_id,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改地址
    public function setother()
    {
        $wifi_ssid = input('wifi_ssid');
        $wifi_password = input('wifi_password');
        $end_time_min = input('end_time_min');
        $end_time_content = input('end_time_content');
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'wifi_ssid' => $wifi_ssid,
            'wifi_password' => $wifi_password,
            'end_time_min' => $end_time_min,
            'end_time_content' => $end_time_content,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改地址
    public function setaddress()
    {
        $address = input('address');
        $latitude = input('lat');
        $longitude = input('lng');
        if (!$address) {
            return $this->error('修改失败');
        }
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'dizhi' => $address,
            'lat' => $latitude,
            'lng' => $longitude,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改拖
    public function setimages()
    {
        $images = input('images');
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'images' => $images,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改logo
    public function setimage()
    {
        $image = input('image');
        if (!$image) {
            return $this->error('修改失败');
        }
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'image' => $image,
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改时间
    public function businesstime()
    {
        $business_stare_time = input('business_stare_time');
        $business_end_time = input('business_end_time');
        if (!$business_stare_time) {
            return $this->error('请输入门店开始时间');
        }
        if (!$business_end_time) {
            return $this->error('请输入门店结束时间');
        }
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'business_stare_time' => $business_stare_time,
            'business_end_time' => $business_end_time
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改电话
    public function setphone()
    {
        $phone = input('phone');
        if (!$phone) {
            return $this->error('请输入门店电话');
        }
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'phone' => $phone
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

    // 修改名称
    public function setname()
    {
        $name = input('name');
        if (!$name) {
            return $this->error('请输入名称');
        }
        $res = Db::name('category')->where([
            'id' => $this->shop_id,
        ])->update([
            'name' => $name
        ]);
        if ($res !== false) {
            return $this->success('修改成功');
        }
        return $this->error('修改失败');
    }

}
